package com.classicmodels.controller;

import com.classicmodels.model.Customer;
import com.classicmodels.model.CustomerDAO;
import com.classicmodels.view.CustomerForm;
import com.classicmodels.view.CustomersList;



public class CustomerController {
    private static CustomerForm customerForm;
    
    

     public static void abrirCustomerForm() throws Exception{
         int aux = CustomerDAO.getCustomerNumber();
         customerForm = new CustomerForm();
         String customerNumber = Integer.toString(aux);
         customerForm.textNumber.setText(customerNumber);
         customerForm.setVisible(true);
         customerForm.textNumber.enable(false);
     }
     
     public static void abrirCustomerFormEdit(String[] customer){
         customerForm = new CustomerForm(customer);
     }
     
     public static void cerrarCustomerForm(){
         customerForm.setVisible(false);
         customerForm.dispose();
     }
     
     public static void cerrarCustomerFormEdit(){
         customerForm.setVisible(false);
         customerForm.dispose();
     }
     
     
     
     
     
     public static void NuevoCliente (String cliente[]) throws Exception{
         Customer p = new Customer();
         int customerNumber = Integer.parseInt(cliente[0]);
         int creditLimit = Integer.parseInt(cliente[11]);
         int salesRepEmployeeNumber = Integer.parseInt(cliente[12]);
         p.setCustomerNumber(customerNumber);
         p.setCustomerName(cliente[1]);
         p.setContactLastName(cliente[2]);
         p.setContactFirstName(cliente[3]);
         p.setPhone(cliente[4]);
         p.setAdressLine1(cliente[5]);
         p.setAdressLine2(cliente[6]);
         p.setCity(cliente[7]);
         p.setState(cliente[8]);
         p.setCountry(cliente[9]);
         p.setPostalCode(cliente[10]);
         p.setCreditLimit(creditLimit);
         p.setSalesRepEmployeeNumber(salesRepEmployeeNumber);
         CustomerDAO.save(p);
         cerrarCustomerForm();
         show_customers();
         
         
     }
  
     public static void show_customers() throws Exception{
        Customer[] customers = CustomerDAO.all();
        CustomersList customersList = new CustomersList(customers);
        customersList.setVisible(true);
    }
  
     
   

    }

